<%@page import="com.metagurukul.metagranth.vo.Answer"%>
<%@page import="com.metagurukul.metagranth.vo.AnswerMetaData"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.metagurukul.metagranth.vo.User"%>
<%@page import="com.metagurukul.metagranth.vo.Tag"%>
<%@page import="com.metagurukul.metagranth.vo.MetaData"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"
	import="com.metagurukul.metagranth.vo.Question"%>
<%@include file="header.jsp"%>
<%
	MetaData metaData = (MetaData) request.getAttribute("metaData");
%>
<%
	Question question = metaData.getQuestion();
	ArrayList<Tag> tagList = metaData.getTagList();
	User user = metaData.getUser();
	String dateTime = question.getDateOfPost().toString();
	String date = dateTime.substring(0, 10);
	String time = dateTime.substring(10);
	ArrayList<AnswerMetaData> answerMetaDataList = metaData
			.getAnswerMetaDataList();
%>
<table width="90%" border="0" align="center">
	<tr>
		<td colspan="3">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="3" class="question-header">
			<%
				out.print(question.getTitle().substring(0, 1).toUpperCase());

				if (question.getTitle().length() > 1) {
					out.println(question.getTitle().substring(1,
							question.getTitle().length()));
				}
				if (question.getIsClosed()) {
					out.println("<span style='color:green;'>[Closed]</span>");
				}
			%>
		</td>
	</tr>
	<tr>
		<td colspan="3" height="50px" valign="top"><hr />
		</td>
	</tr>
	<tr>
		<td colspan="3" class="question-discription">
			<%
				Integer questionRow = (question.getQuestion().length() / 102) + 1;
			%> <textarea rows="<%=questionRow%>" class="code-textarea"
				readonly="readonly"><%=question.getQuestion()%></textarea>
		</td>
	</tr>

	<tr>
		<td colspan="3" height="20px">&nbsp;</td>
	</tr>
	<%
		if (tagList.size() > 0) {
	%>
	<tr>
		<td colspan="3" align="left" valign="bottom" height="50px">
			<%
				for (Tag tag : tagList) {
			%> <a href="searchQuestionByTag.do?tagFilterId=<%=tag.getTagid()%>"
			class="post-tag" title="" rel="tag"><%=tag.getTagName()%></a> <%
 	}
 %>
		</td>
	</tr>
	<%
		}
	%>
	<tr>
		<td align="right" valign="bottom" colspan="3" class="posted">Posted
			By : <%=user.getName()%></td>
	</tr>
	<tr>
		<td align="right" class="posted" colspan="3">Time :<%=time.substring(0, time.length() - 2)%>&nbsp;&nbsp;Date
			: <%=date%></td>
	</tr>
	<tr>
		<td colspan="3" class="question-header"><%=answerMetaDataList.size()%>
			Answers</td>
	</tr>
	<tr>
		<td colspan="3"><hr />
		</td>
	</tr>
	<tr>
		<td colspan="3" height="30px">&nbsp;</td>
	</tr>
	<%
		for (AnswerMetaData answerMetaData : answerMetaDataList) {
			Answer answer = answerMetaData.getAnswer();
			User answeredUser = answerMetaData.getUser();
			String answerDateTime = question.getDateOfPost().toString();
			String answerDate = dateTime.substring(0, 10);
			String answerTime = dateTime.substring(10);
	%>
	<tr>
		<td width="32" valign="middle" colspan="1">
			<%
				if (answer.isIsapproved()) {
			%> <img src="images/valid.png" width="32" height="32" /> <%
 	}
 %>
		</td>
		<%
			Integer ansrow = (answer.getAnswer().length() / 102) + 1;
		%>
		<td colspan="2" valign="top" class="question-discription"><textarea
				rows="<%=ansrow%>" class="code-textarea" readonly="readonly"><%=answer.getAnswer()%></textarea>
		</td>
	</tr>
	<tr>
		<td align="left" valign="bottom" colspan="3" height="30px">&nbsp;</td>
	</tr>
	<tr>
		<td align="left" valign="bottom" colspan="3" class="posted">Posted
			By : <%=answeredUser.getName()%></td>
	</tr>
	<tr>
		<td align="left" class="posted" colspan="3" height="40px;"
			valign="top">Time : <%=answerTime.substring(0, answerTime.length() - 2)%>&nbsp;&nbsp;Date
			: <%=answerDate%></td>
	</tr>
	<tr>
		<td colspan="3" style="border-top: 1px dotted #000000;" height="30px"
			valign="middle">&nbsp;</td>
	</tr>

	<%
		}
		if (!question.getIsClosed()) {
	%>
	<tr>
		<td width="100%" colspan="3" align="left">
			<form action="postanswer.do" method="POST" name="post-from">
				<input type="hidden" name="questionId"
					value="<%=question.getQuesId()%>">
				<section id="main">
				<div class="module_content">
					<article class="module width_full"> <header>
					<h3>Post Your Answer</h3>
					</header>
					<div class="module_content">
						<fieldset>
							<label>Answer</label>
							<textarea rows="12" name="answerdescription"
								id="answerdescription"></textarea>
						</fieldset>
						<div class="clear"></div>
						<div class="submitdiv">
							<input type="submit" value="" class="btn_ans_submit" onclick="return answerForm()">
						</div>
						<div class="clear"></div>
					</div>
					<footer> </footer> </article>
				</div>
				</section>
			</form>
		</td>
	</tr>
	<tr>
		<td colspan="3" height="50px" valign="top">&nbsp;
		</td>
	</tr>
	<%
		}
	%>
</table>
<%@include file="footer.jsp"%>


